<!--  Copyright 2020 Zhejiang Lab and Zhejiang University. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================
-->

<template>
  <div>
    <b-row>
      <b-col class="mt-1" md="2">算法：</b-col>
      <b-col class="mt-1" md="4">{{algorithms.alg_name}}</b-col>
      <b-col class="mt-1" md="2">创建时间：</b-col>
      <b-col class="mt-1" md="4">{{task_details.created_time}}</b-col>
      <b-col class="mt-1" md="2">视觉任务：</b-col>
      <b-col class="mt-1" md="4">{{task_details.tasks}}</b-col>
      <b-col class="mt-1" md="2">开始时间：</b-col>
      <b-col class="mt-1" md="4">{{task_details.started_time}}</b-col>
      <b-col class="mt-1" md="2">任务状态:</b-col>
      <b-col class="mt-1" md="4">{{task_state()}}</b-col>
      <b-col class="mt-1" md="2">完成时间：</b-col>
      <b-col class="mt-1" md="4">{{task_details.completed_time}}</b-col>
      <b-col class="mt-1" v-if="Number(task_details.progress)==1" md="4">{{task_details.score}}</b-col>
    </b-row>

    <b-row>
    <b-col class="mt-1" md="2">数据集：</b-col>
    <b-col class="mt-1">{{task_details.datasets}}</b-col>
    </b-row>

    <b-row>
    <b-col class="mt-1" md="2">教师模型：</b-col>
    <b-col class="mt-1">{{task_details.teacher_models}}</b-col>
    </b-row>

    <b-row v-if="task_details.student_models">
    <b-col class="mt-1" md="2">学生模型：</b-col>
    <b-col class="mt-1">{{task_details.student_models}}</b-col>
    </b-row>
    
    <b-row>
      <b-col class="mt-1" md="2">算法字段：</b-col>
      <b-col>
        <b-badge
          v-for="field in algorithms.fields"
          :key="field.id"
          style="marginRight: 2px"
          variant="info"
        >{{field.field_name}}: {{field.field_value}}</b-badge>
      </b-col>
    </b-row>

    <b-row>
    <b-col class="mt-1" md="2">训练进度：</b-col>
    <b-col class="mt-1">
        <b-progress
          :style="{marginTop:'7px',marginBottom:'0px'}"
          :animated="Number(task_details.progress)!=1"
          :value="task_details.progress"
          :max="1"
          :precision="2"
          :variant="task_details.runtime_error?'danger':'success'"
          show-progress
        ></b-progress>
    </b-col>
    </b-row>

    <hr>

    <b-row>
      <b-col class="mt-4" md="6">
        <b-button variant="outline-danger" @click="deleteReorgTasks([task_details.id])">删除</b-button>
        <b-button
          v-if="Number(task_details.progress)==1"
          variant="outline-success"
          @click="download(task_details.url)"
        >下载</b-button>
      </b-col>
    </b-row>
  </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from "vuex";
import { download } from "../store/utils";

export default {
  name: "BasicTaskInfo",
  computed: mapState("task_detail", {
    task_details: state => state.task_details,
    algorithms: state => state.algorithms,

  }),
  methods: {
    ...mapActions("task_detail", ["deleteReorgTasks"]),
    download,
    task_state() {
      if ("state" in this.task_details && this.task_details.state=="failed") 
        return "失败"
      if ("url" in this.task_details)
        return "完成"
      if (this.task_details.progress==0)
        return "等待中"
      else
        return "进行中"
    }
  }
};
</script>